#!/bin/bash
# Kylin ISO自动挂载及Yum源配置脚本

# 步骤1：创建挂载目录
mkdir -p /mnt/cdrom
umount /mnt/cdrom

# 步骤2：挂载ISO镜像
mount -o loop /home/Kylin-Server-V10-SP3-2403-Release-20240426-x86_64.iso /mnt/cdrom

# 步骤3：配置开机自动挂载
if ! grep -q "Kylin-Server-V10-SP3-2403-Release" /etc/fstab; then
    echo "/home/Kylin-Server-V10-SP3-2403-Release-20240426-x86_64.iso  /mnt/cdrom  iso9660  loop  0  0" >> /etc/fstab
fi

# 步骤4：备份原有yum源并创建新配置
YUM_REPO_DIR="/etc/yum.repos.d"
mkdir -p $YUM_REPO_DIR/bak
mv $YUM_REPO_DIR/*.repo $YUM_REPO_DIR/bak/ 2>/dev/null

cat > $YUM_REPO_DIR/Kylin-base.repo <<EOF
[base]
name=Kylin-os
baseurl=file:///mnt/cdrom/
enabled=1
gpgcheck=0
EOF

# 步骤5：更新yum缓存
rm -rf /var/cache/yum/*
yum clean all
yum makecache

echo "脚本执行完成，请验证以下内容："
echo "1. 检查挂载状态: df -h | grep cdrom"
echo "2. 检查Yum源列表: yum repolist"